package tech.yunjing.train.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tech.yunjing.train.entity.SmallRedPacket;
import tech.yunjing.train.service.ReceiveRedPacketService;
import tech.yunjing.train.util.JsonResult;

import java.util.List;


/**
 * 抢红包的controller
 * Created by zlc on 2017/6/8.
 */
@RestController
@RequestMapping("/receiveRedPacket")
public class ReceiveRedPacketController extends BaseController {


    @Autowired
    private ReceiveRedPacketService receiveRedPacketService;


    /**
     * 用户进行抢红包操作
     *
     * @param redPacketName  红包名字
     * @param sendAccount    发红包用户账号
     * @param receiveAccount 抢红包用户账号
     * @return
     */
    @RequestMapping(value = "/receive", method = RequestMethod.POST)
    public JsonResult<Double> ReceiveRedPacket(String redPacketName, String sendAccount, String receiveAccount) {
        return new JsonResult<Double>(receiveRedPacketService.receiveMoney(redPacketName, sendAccount, receiveAccount));
    }

    /**
     * 根据用户账户和大红包名称查询所有的小红包
     *
     * @param redPacketName 大红包名
     * @param userAccount   用户账户
     * @return
     */
    @RequestMapping(value = "/findAll", method = RequestMethod.POST)
    public JsonResult<List<SmallRedPacket>> findAll(String redPacketName, String userAccount) {
        return new JsonResult<List<SmallRedPacket>>(receiveRedPacketService.findAll(redPacketName, userAccount));
    }

    /**
     * 根据用户账户和大红包名称逻辑删除小红包
     *
     * @param redPacketName 大红包名称
     * @param userAccount   用户账户
     * @return true表示成功
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public JsonResult<Integer> removeSmallRedPacket(String redPacketName, String userAccount) {
        return new JsonResult<Integer>(receiveRedPacketService.removeSmallRedPacket(redPacketName, userAccount));
    }
}
